#!/bin/bash

cfgtest=
name=
shared=
o=
for f in "$@"; do
	case "${f}" in
		QtCore | QtNetwork | QtGui | QtPrintSupport )
			test "${o}" && name="${f}"
			o=
			;;
		cfgtest_${name}.o )
			test "${name}" && cfgtest=true
			o=
			;;
		-shared )
			shared=true
			o=
			;;
		-o )
			o=true
			;;
		* )
			o=
			;;
	esac
done

cfgtest_QtCore="shared"
cfgtest_QtNetwork=
cfgtest_QtGui="PyQt_Accessibility PyQt_OpenGL PyQt_Desktop_OpenGL"
cfgtest_QtPrintSupport=

if test "${cfgtest}"; then
	cat <<-EOF > "${name}"
		#!/bin/sh
		test "\$#" -ge 1 || exit 1
		echo $(eval echo \$$(echo cfgtest_${name})) | tr ' ' '\n' > \$1
	EOF
	chmod 0755 "${name}"
	exit 0
fi

libs=
test "${shared}" && libs="-L@TERMUX_PREFIX@/lib -lpython@PYTHON_VERSION@"
exec @CXX@ "$@" ${libs}
